# Maintainer: MVZ Labor Ludwigsburg <edv@mvz-labor-lb.de>

_realname=zint
pkgbase=mingw-w64-${_realname}
pkgname=(
  "${MINGW_PACKAGE_PREFIX}-zint"
  "${MINGW_PACKAGE_PREFIX}-zint-qt"
)
pkgver=2.15.0
pkgrel=1
pkgdesc='Barcode encoding library supporting over 50 symbologies (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="http://zint.org.uk/"
msys2_repository_url="https://github.com/zint/zint"
license=('spdx:GPL-3.0-or-later')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-qt6-svg"
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
)
source=(
  "https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}-src.tar.gz"
)
sha256sums=('bce37d9b86e6127cac63c8b6267ac421116d4ac086519d726eb724f5462d98c7')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake -S ${_realname}-${pkgver}-src \
      -B build-${MSYSTEM} \
      -G Ninja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DZINT_QT6=ON \
      "${extra_config[@]}"

  ${MINGW_PREFIX}/bin/cmake --build build-${MSYSTEM}
}

package_zint() {
  depends=("${MINGW_PACKAGE_PREFIX}-libpng")

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install build-${MSYSTEM}

  rm "${pkgdir}${MINGW_PREFIX}/bin/zint-qt.exe"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}-src/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}

package_zint-qt() {
  pkgdesc='Zint Barcode Studio GUI (mingw-w64)'
  depends=("${MINGW_PACKAGE_PREFIX}-qt6-base"
           "${MINGW_PACKAGE_PREFIX}-qt6-tools"
           "${MINGW_PACKAGE_PREFIX}-zint")

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install build-${MSYSTEM}/backend_qt
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install build-${MSYSTEM}/frontend_qt

  rm -r "${pkgdir}${MINGW_PREFIX}/include"
  rm -r "${pkgdir}${MINGW_PREFIX}/lib"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :


for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
